package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark69Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark69 extends BaseMark {

    LayoutWatermark69Binding binding;

    public Mark69(@NonNull Context context) {
        super(context);
    }

    public Mark69(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark69(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark69Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.bottom);
        } else {
            binding = LayoutWatermark69Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title69", binding.binding1);
        setText(binding.binding3, "time69", binding.binding2);
        setTime(binding.binding5, new SimpleDateFormat("yyyy-MM-dd"));
        setWeek(binding.binding4);
        setTime(binding.binding3, new SimpleDateFormat("HH:mm"));

        setText(binding.binding7, "person69", binding.binding6);
        setText(binding.binding9, "type69", binding.binding8);
        setText(binding.binding11, "area69", binding.binding10);
        setText(binding.binding13, "line69", binding.binding12);
        setText(binding.binding15, "weather69", binding.binding14);
        setText(binding.binding17, "jingwei69", binding.binding16);
        setText(binding.binding19, "didian69", binding.binding18);
        setText(binding.binding21, "beizhu69", binding.binding20);

        setText(binding.binding23, "unit69", binding.binding22);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title69", "标题"));
        list.add(new EditItem("time69", "时间", true));
        list.add(new EditItem("person69", "巡检人"));
        list.add(new EditItem("type69", "巡检类型"));
        list.add(new EditItem("area69", "清理区域"));
        list.add(new EditItem("line69", "巡检线路"));
        list.add(new EditItem("weather69", "天气"));
        list.add(new EditItem("jingwei69", "经纬度"));
        list.add(new EditItem("didian69", "巡检地点"));
        list.add(new EditItem("beizhu69", "备注"));

        list.add(new EditItem("unit69", "巡检单位"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding5, new SimpleDateFormat("yyyy-MM-dd"));
            setWeek(binding.binding4);
            setTime(binding.binding3, new SimpleDateFormat("HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
